home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 1 code / the Palette Manager / Sample.f / Palette.source next >
Encoding:
Text File  |  1989-09-20  |  3.7 KB  |  138 lines  |  [TEXT/MPS ]

  1.  
  2.  
  3.  
  4. FUNCTION Make14RedPalette: PaletteHandle;
  5.     VAR
  6.         i:    LONGINT;
  7.         ph:    PaletteHandle;
  8.         c:    RGBColor;
  9.                 
  10.     BEGIN
  11.         ph := NewPalette(14,NIL,pmTolerant,4000);
  12.         { 4000 is about 1/16 of 64k   *)
  13.         { should check for NIL result *)
  14.  
  15.         c.green := 0;
  16.         c.blue  := 0;
  17.  
  18.         FOR i:= 0 TO 13
  19.         DO
  20.         BEGIN
  21.             { range red component from 1/14 to 14/14 *)
  22.             { i is a longint, and so can safely be multiplied by 65535 *)
  23.             c.red := (i+1)*65535 DIV 14;
  24.             SetEntryColor(ph,i,c);
  25.         END;
  26.  
  27.         Make14RedPalette := ph;
  28.     END;
  29.  
  30.  
  31.         myPalette := Make14RedPalette;
  32.         SetPalette(myWindow,myPalette);
  33.  
  34.  
  35.  
  36.  
  37.     FUNCTION MakeRedPalette: PaletteHandle;
  38.     VAR
  39.         i:    LONGINT;
  40.         ph:    PaletteHandle;
  41.         c:    RGBColor;
  42.                 
  43.     BEGIN
  44.         ph := NewPalette(254+14,NIL,0,0);
  45. { should check for NIL result *)
  46.  
  47.         c.green := 0;
  48.         c.blue := 0;
  49.  
  50. {    Make fourteen reds that are inhibited on all *)
  51. {    screens except four-bit color *)
  52.         FOR i:=0 TO 13
  53.         DO
  54.         BEGIN
  55. { range red component from 1/14 to 14/14 *)
  56. { i is a longint, and so can safely be multiplied by 65535 *)
  57.             c.red := (i+1)*65535 DIV 14;
  58.             SetEntryColor(ph,i,c);
  59.             SetEntryUsage(ph,i,pmTolerant+pmInhibitC2+
  60.                     pmInhibitG2+pmInhibitG4+
  61.                     pmInhibitC8+pmInhibitG8,4000);
  62.         END;
  63.  
  64. {    Make 254 reds that are inhibited on all *)
  65. {    screens except eight-bit color *)
  66.         FOR i:=0 TO 254
  67.         DO
  68.         BEGIN
  69. { range red component from 1/14 to 14/14 *)
  70. { i is a longint, and so can safely be multiplied by 65535 *)
  71.             c.red := (i+1)*65535 DIV 254;
  72.             SetEntryColor(ph,14+i,c);
  73.             SetEntryUsage(ph,14+i,pmTolerant+pmInhibitC2+
  74.                     pmInhibitG2+pmInhibitG4+
  75.                     pmInhibitC4+pmInhibitG8,0);
  76.         END;
  77.  
  78.         MakeRedPalette := ph;
  79.     END;
  80.  
  81.  
  82.  
  83. SetEntryUsage(ph,1,pmCourteous,0);    
  84.     { The color is “courteous,”    activating the palette will never    *)
  85.     { cause a change in a screen’s color table. This is useful only    *)
  86.     { for “naming” the color, in this case to 1. PmForeColor(1) and    *)
  87.     { PmBackColor(1) are two ways to use this color.            *)
  88.  
  89. SetEntryUsage(ph,2,pmTolerant,10000);
  90.     { The color is “tolerant,” activating the palette will ensure    *)
  91.     { some index in the screen’s color table is within 10000 in each    *)
  92.     { RGB component from palette entry 2.                    *)
  93.  
  94. SetEntryUsage(ph,3,pmAnimated,0);
  95.     { The color is “animated,” activating the palette will reserve    *)
  96.     { an index from the screen’s color table to be owned by this    *)
  97.     { palette (if the screen is indexed). If the color is changed    *)
  98.     { with AnimateEntry then any previous drawing done with that    *)
  99.     { entry will change.                                *)
  100.  
  101. SetEntryUsage(ph,4,pmExplicit,0);
  102.     { The color is “explicit,” any drawing done with this entry will    *)
  103.     { draw in device index 4, because this entry is the 4th color    *)
  104.     { in the palette. This is mostly useful for monitoring the color    *)
  105.     { environment.                                    *)
  106.  
  107. SetEntryUsage(ph,5,pmExplicit+pmTolerant,0);
  108.     { The color is both “explicit” and “tolerant.” Activating the    *)
  109.     { palette will ensure that device index 5 exactly matches        *)
  110.     { the palette’s color 5 (because the tolerance here is 0).        *)
  111.  
  112. SetEntryUsage(ph,6,pmExplicit+pmAnimated,0);
  113.     { The color is both “explicit” and “animated.” Activating the    *)
  114.     { palette will reserve screen index 6 for this palette’s use.    *)
  115.     { The color may be modified with AnimateEntry and            *)
  116.     { AnimatePalette.                                *)
  117.  
  118. SetEntryUsage(ph,7,pmAnimated+pmInhibitC8+pmInhibitG8,0);
  119.     { The color is “animated” on any screen other than an 8-bit    *)
  120.     { color or an 8-bit gray-scale device. On those devices, the    *)
  121.     { behaves as a courteous color.                        *)
  122.  
  123.             
  124.  
  125.  
  126.  
  127. myPP:    PixPatHandle;
  128. myCT:    CTabHandle;
  129.  
  130. myPP := GetPixPat(16);    { Gets the system color desktop pattern    *)
  131. myCT := myPP^^.patMap^^.pmTable
  132.     FOR j := 0 TO myCT^^.ctSize
  133.     DO
  134.         myCT^^.ctTable[j].value := j;
  135.  
  136.     myCT^^.ctFlags := myCT^^.ctFlags+$4000;    { .ctFlags aka .transinde *)
  137.                     { would be bad if bit 14 were already set   *)
  138.